package org.todo.controller;


import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import org.springframework.web.portlet.bind.PortletRequestUtils;
import org.springframework.web.portlet.mvc.AbstractController;
import org.todo.service.TodoService;

/**
 * Controller that handles the delete action requests for todo items
 * @author Matthias Braunhofer
 */
public class DeleteTodoController extends AbstractController {
    //injected dependency
    private TodoService todoService;

    /**
     * Handles the delete action request for a certain todo item
     * @param request
     * @param response
     * @throws java.lang.Exception
     */
    @Override
    protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
        int todoId = PortletRequestUtils.getIntParameter(request, "todoId");
        todoService.deleteTodo(todoId);
        
        //map rendering phase to todosController
        response.setRenderParameter("action", "todos");
    }

    public void setTodoService(TodoService todoService) {
        this.todoService = todoService;
    }
}
